home *** CD-ROM | disk | FTP | other *** search
/ Trusted Irix /B 4.0.4 / Trusted-Irix B-4.0.1.iso / dist / eoe1.idb / etc / shutdown.z / shutdown
Text File  |  1992-04-03  |  2KB  |  128 lines

  1. #! /bin/sh
  2. #Tag 0x00000f00
  3. #ident    "$Revision: 1.14 $"
  4.  
  5. #    Sequence performed to change the init stat of a machine.
  6.  
  7. #    This procedure checks to see if you are permitted and allows an
  8. #    interactive shutdown.  The actual change of state, killing of
  9. #    processes and such are performed by the new init state, say 0,
  10. #    and its /etc/rc0.
  11.  
  12. #    Usage:  shutdown [ -y ] [ -g<grace-period> ] [ -i<init-state> ]
  13.  
  14. #!    chmod +x ${file}
  15.  
  16. #    Check the user id.
  17. if [ -x /usr/bin/id ]
  18. then
  19.     eval `id  |  sed 's/[^a-z0-9=].*//'`
  20.     if [ "${uid:=0}" -ne 0 ]
  21.     then
  22.             echo "$0:  Only root can run /etc/shutdown."
  23.         exit 2
  24.     fi
  25. fi
  26.  
  27. grace=60
  28. askconfirmation=yes
  29. initstate=0
  30. while [ $# -gt 0 ]
  31. do
  32.     case $1 in
  33.     -g[0-9]* )
  34.         grace=`expr "$1" : '-g\(.*\)'`
  35.         ;;
  36.     -i[Ss016] )
  37.         initstate=`expr "$1" : '-i\(.*\)'`
  38.         ;;
  39.     -i[2345] )
  40.         initstate=`expr "$1" : '-i\(.*\)'`
  41.         echo "$0:  Initstate $initstate is not for system shutdown"
  42.         exit 1
  43.         ;;
  44.     -y )
  45.         askconfirmation=
  46.         ;;
  47.     -* )
  48.         echo "Illegal flag argument '$1'"
  49.         exit 1
  50.         ;;
  51.     * )
  52.         echo "Usage:  $0 [ -y ] [ -g<grace> ] [ -i<initstate> ]"
  53.         exit 1
  54.     esac
  55.     shift
  56. done
  57.  
  58. if [ -n "${askconfirmation}" -a -x /etc/ckbupscd ]
  59.     then
  60.     #    Check to see if backups are scheduled at this time
  61.     BUPS=`/etc/ckbupscd`
  62.     if [ "$BUPS" != "" ]
  63.         then
  64.         echo "$BUPS"
  65.         echo "Do you wish to abort this shutdown and return to 
  66. command level to do these backups? [y, n] \c"
  67.         read YORN
  68.         if [ "$YORN" = "y" -o "$YORN" = "Y" ]
  69.             then 
  70.             exit 1
  71.         fi
  72.     fi
  73. fi
  74.  
  75. if [ -z "${TZ}"  -a  -r /etc/TIMEZONE ]
  76. then
  77.     . /etc/TIMEZONE
  78. fi
  79.  
  80. echo 'Shutdown started.     \c'
  81. date
  82.  
  83. sync
  84. cd /
  85.  
  86. trap "exit 1"  1 2 15
  87.  
  88. a="`who  |  wc -l`"
  89. if [ ${a} -gt 1  -a  ${grace} -gt 0 ]
  90. then
  91.     if [ -x /etc/wall ]
  92.     then
  93.         su adm -c /etc/wall<<-!
  94.             The system will be shut down in ${grace} seconds.
  95.             Please log off now.
  96.         !
  97.     fi
  98.     sleep ${grace}
  99. fi
  100.  
  101. if [ -x /etc/wall ]
  102. then
  103.     /etc/wall <<-!
  104.         THE SYSTEM IS BEING SHUT DOWN! Log off now.
  105.     !
  106. fi
  107. sleep ${grace}
  108.  
  109. if [ ${askconfirmation} ]
  110. then
  111.     echo "Do you want to continue with the shutdown? (y or n):   \c"
  112.     read b
  113. else
  114.     b=y
  115. fi
  116. if [ "$b" != "y" ]
  117. then
  118.     if [ -x /etc/wall ]
  119.     then
  120.         /etc/wall <<-\!
  121.             False Alarm:  The system will not be brought down.
  122.         !
  123.     fi
  124.     echo 'Shut down aborted.'
  125.     exit 1
  126. fi
  127. /etc/init ${initstate}
  128.